﻿
using System.Diagnostics;

// 中间件
namespace mvc6.Middlewares
{
    /// <summary>
    /// 1，编写一个中间件
    /// 2,然后注册
    /// </summary>
    public class MyMiddleware 
    {

        private readonly RequestDelegate _next;

        public MyMiddleware(RequestDelegate next)
        {
            _next = next;
        }


        public async Task InvokeAsync(HttpContext context)
        {

            PathString path = context.Request.Path;
            if (path.Equals(""))
            {

            }
            else
            {
                Console.WriteLine("-----> Before");
                var s = new Stopwatch();
                s.Start();
                await _next.Invoke(context);
                s.Stop();

                Console.WriteLine($"耗时:{s.ElapsedMilliseconds}");
                Console.WriteLine("----> After");
            }

            
        }
    }
}
